# encoding: utf-8
"""
@author: Dirac
@file: auth.py
@time: 2020/8/4 10:57
@desc:
"""
from django.utils.deprecation import MiddlewareMixin

from web import models


class AuthMiddleWare(MiddlewareMixin):

    @staticmethod
    def process_request(request):
        """
        如果用户已登录，则 request 中赋值
        :param request:
        :return:
        """
        user_id = request.session.get('user_id', 0)
        user_object = models.UserInfo.objects.filter(id=user_id).first()
        request.tracer = user_object
